<?php
class collegeModel extends RPHP_Model
{

    public function getCategory($fucaid = 2)
    {
        $sql = "SELECT `caid`,`name` FROM {$this->_prefix['primary']}article_category WHERE `fucaid`=" . $fucaid . " ORDER BY `sort` ASC,`caid` ASC";
        $tmp = $this->sql($sql);
        if ($tmp) {

            $data['caid'] = 0;

            foreach ($tmp as $r) {

                if ($data['caid'] == 0) {
                    $data['caid'] = $r['caid'];
                }

                $data['list'][$r['caid']] = $r['name'];
            }

            return $data;
        }
    }

    public function getList($para, $page, $pagesize = 10)
    {
        $where = " WHERE `caid`=" . $para['caid'] . " AND `is_open`=1";

        $sql = "SELECT COUNT(`article_id`) AS `cnt` FROM {$this->_prefix['primary']}article " . $where;
        $cnt = $this->db->getone($sql);

        if ($cnt > 0) {
            $start = ($page - 1) * $pagesize;
            //默认排序
            $orderby = "`article_id` DESC";
            //查询订单信息
            $sql = "SELECT `article_id`,`title`,`keywords`,`urls`,`add_time` FROM {$this->_prefix['primary']}article  " . $where . " ORDER BY " . $orderby . " LIMIT " . $start . "," . $pagesize;
            $rs  = $this->sql($sql);
        }

        return array(
            'page'    => $page,
            'maxpage' => ceil($cnt / $pagesize),
            'count'   => $cnt,
            'data'    => $rs,
            'para'    => $para,
        );
    }

}
